//
//  HSYQRBoxView.m
//  HSY
//
//  Created by 陈浩 on 2017/4/10.
//  Copyright © 2017年 金开门. All rights reserved.
//

#import "HSYQRBoxView.h"

#define CORNERLENGTH 15


@implementation HSYQRBoxView

-(void)drawInContext:(CGContextRef)ctx{
    UIBezierPath * focusPath = [self createBezierPathWithBounds:self.bounds focusRect:self.bounds];
    CGContextAddPath(ctx, focusPath.CGPath);
    CGContextSetFillColorWithColor(ctx, [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5].CGColor);
    CGContextEOFillPath(ctx);
    
    CGContextSetStrokeColorWithColor(ctx, [UIColor greenColor].CGColor);
    CGContextSetLineWidth(ctx,2.0);
    
    
    CGContextMoveToPoint(ctx, self.bounds.origin.x + CORNERLENGTH, self.bounds.origin.y);
    CGContextAddLineToPoint(ctx, self.bounds.origin.x,self.bounds.origin.y);
    CGContextAddLineToPoint(ctx, self.bounds.origin.x, self.bounds.origin.y + CORNERLENGTH);
    CGContextStrokePath(ctx);
    
    CGContextMoveToPoint(ctx, self.bounds.origin.x + self.bounds.size.width - CORNERLENGTH, self.bounds.origin.y);
    CGContextAddLineToPoint(ctx, self.bounds.origin.x + self.bounds.size.width, self.bounds.origin.y);
    CGContextAddLineToPoint(ctx, self.bounds.origin.x + self.bounds.size.width, self.bounds.origin.y + CORNERLENGTH);
    CGContextStrokePath(ctx);
    
    CGContextMoveToPoint(ctx, self.bounds.origin.x + self.bounds.size.width, self.bounds.origin.y + self.bounds.size.height - CORNERLENGTH);
    CGContextAddLineToPoint(ctx,self.bounds.origin.x + self.bounds.size.width,self.bounds.origin.y + self.bounds.size.height);
    CGContextAddLineToPoint(ctx, self.bounds.origin.x + self.bounds.size.width - CORNERLENGTH, self.bounds.origin.y + self.bounds.size.height);
    CGContextStrokePath(ctx);
    
    CGContextMoveToPoint(ctx, self.bounds.origin.x, self.bounds.origin.y - CORNERLENGTH + self.bounds.size.height);
    CGContextAddLineToPoint(ctx,self.bounds.origin.x,self.bounds.origin.y+self.bounds.size.height);
    CGContextAddLineToPoint(ctx, self.bounds.origin.x + CORNERLENGTH, self.bounds.origin.y + self.bounds.size.height);
    CGContextStrokePath(ctx);
    
    UIBezierPath * beziper = [UIBezierPath bezierPathWithRect:self.bounds];
    CGContextAddPath(ctx, beziper.CGPath);
    CGContextSetStrokeColorWithColor(ctx, [UIColor whiteColor].CGColor);
    CGContextSetLineWidth(ctx, 0.5);
    CGContextStrokePath(ctx);
}

-(UIBezierPath *)createBezierPathWithBounds:(CGRect)bounds focusRect:(CGRect)focusRect{
    UIBezierPath * bezierPath = [UIBezierPath bezierPathWithRect:bounds];
    UIBezierPath * focusPath = [UIBezierPath bezierPathWithRect:focusRect];
    [bezierPath appendPath:focusPath];
    return bezierPath;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
